package Sort;

public class MyQuick2 {

    //双边排序
    public static void quick(int[] arr){
        recursion(arr,0,arr.length - 1);

    }
    private static void recursion(int[] arr,int left,int right){
        if (left >= right){
            return;
        }

        int mid = benchmark(arr,left,right);
        recursion(arr,left,mid - 1);
        recursion(arr,mid + 1,right);
    }
    private static int benchmark(int[] arr,int left,int right){
        int temp = arr[left];
        int i = left;
        int j = right;
        while (i < j){
            while (i < j && arr[j] > temp){
                j--;
            }

            while (i < j && arr[i] <= temp){
                i++;
            }

            swap(arr,i,j);
        }
        swap(arr,left,i);
        return i;
    }

    private static void swap(int[] arr,int i,int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
